<input type="hidden" value="ARTICLE" name="site[<?PHP echo $nb;?>]<?PHP if(isset($voxbloc)) echo '[bloc]['.$voxbloc.']';?>[question][<?PHP echo $question['id_question'];?>][type]" />
<div class="input_article" style="clear:both;"><?PHP
	// on construit le tableau des reponses avec comme indice l'id des articles
	$tableau_reponse = Array();
	foreach ($question['reponses'] as $reponse) {
		$tableau_reponse[$reponse['id_article']] = $reponse;
	}

	foreach(($questionsavecarticles[$question['id_question']]['result']) as $ligne) {
		$options[] = $ligne['articles'];
	}
?>

	<label><?PHP echo $question['libelle_question'];?></label>
	<div id="<?PHP echo "site".$nb."_listeArticles".$question['id_question']; ?>">
		<input name="site[<?PHP echo $nb;?>]<?PHP if(isset($voxbloc)) echo '[bloc]['.$voxbloc.']';?>[question][<?PHP echo $question['id_question'];?>][qte][]" min="0" type="number"
				style="width:50px; text-align: right;">
		<select onchange="appliquerMoteur(<?PHP echo $nb;?>)" name="site[<?PHP echo $nb;?>]<?PHP if(isset($voxbloc)) echo '[bloc]['.$voxbloc.']';?>[question][<?PHP echo $question['id_question'];?>][art][]">
			<option value="0">Selectionnez un article...</option>
			<?PHP // cr�ation du script pour ajouter les r�ponses � la base de fait
				$script_article = 'var article_'.$nb.'_'.$question['id_question'].' = [';
				$script = '';
				
				foreach($options as $ligne) {
					$script_article .= php2js($ligne).',';
					// ajout des réponses
					if(isset($tableau_reponse[$ligne['id_article']])) {
						echo '<option id="site'.$nb.'_reponse_'.$tableau_reponse[$ligne['id_article']]['id_reponse'].'" value="'.$ligne['id_article'].'">'.$ligne['description_article'].'</option>';
						$script .= 'ajouterFait('.$nb.', \'site'.$nb.'_reponse_'.$tableau_reponse[$ligne['id_article']]['id_reponse'].'\', document.getElementById(\'site'.$nb.'_reponse_'.$tableau_reponse[$ligne['id_article']]['id_reponse'].'\'));'."\n";
						$script .= "baseDeFait[$nb]['site".$nb."_question_".$question['id_question']."_reponses'].push(document.getElementById('site".$nb."_reponse_".$tableau_reponse[$ligne['id_article']]['id_reponse']."'));";
					}
					else {
						echo '<option value="'.$ligne['id_article'].'">'.$ligne['description_article'].'</option>';
					}
				}
				$script_article .= "]\n";
			?>
		</select>
		<br />
		<img style="margin-left:250px; cursor:pointer" src="../img/add.png" onclick="ajouterChoixArticle(this, this.parentNode.id, <?PHP echo 'article_'.$nb.'_'.$question['id_question']; ?>, '<?PHP echo 'site['.$nb.'][bloc]'.(isset($voxbloc)?'['.$voxbloc.']':'').'[question]['.$question['id_question'].'][qte][]'; ?>', '<?PHP echo 'site['.$nb.'][bloc]'.(isset($voxbloc)?'['.$voxbloc.']':'').'[question]['.$question['id_question'].'][art][]'; ?>', <?PHP echo $nb; ?>);" />
	</div>
	<script type="text/javascript">
		<?PHP
			// on affiche le script qui ajoute les faits
			echo $script_article;
			echo $script;
			// on écrit toute les règles en parcourant le tableau des règles
			foreach($tableau_reponse as $reponse) {
				// pour chaque réponse, on parcours son tableau d'action
				foreach($reponse['actions'] as $action) {
					if($action['id_reponse'] != null) {
						// si l'action a pour but d'activer, alors on active
						if($action['active_question']) {
							echo "ajouterRegle(function(){return $(baseDeFait[".$nb."]['site".$nb."_question_".$question['id_question']."']).is(':visible') && baseDeFait[".$nb."]['site".$nb."_reponse_".$action['id_reponse']."'].selected;}, function(){afficherElement(".$nb.", 'site".$nb."_question_".$action['id_question']."');});";
						}
						else {
							echo "ajouterRegle(function(){return $(baseDeFait[".$nb."]['site".$nb."_question_".$question['id_question']."']).is(':visible') && baseDeFait[".$nb."]['site".$nb."_reponse_".$action['id_reponse']."'].selected;}, function(){cacherElement(".$nb.", 'site".$nb."_question_".$action['id_question']."');});";
						}
					}
				}
				// on parcours également son tableau de change_statut
				foreach($reponse['change_statut'] as $change_statut) {
					// on ajoute au script le changement de statut
					echo "ajouterRegle(function(){return $(baseDeFait[".$nb."]['site".$nb."_question_".$question['id_question']."']).is(':visible') && baseDeFait[".$nb."]['site".$nb."_reponse_".$change_statut['id_reponse']."'].selected;}, function(){changerStatut(".$nb.", 'site".$nb."_reponse_".$change_statut['id_reponse_statut_change_par']."', '".$change_statut['libelle_statut']."', ".$change_statut['priorite'].");});\n";
				}
			}
		?>
	</script>
</div>